﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace JU.Common
{
    public class CommonHelper
    {
        /// <summary>
        /// 获得栈堆中指定的方法名与该方法所在实例的类名
        /// </summary>
        /// <param name="index">指定栈</param>
        /// <returns>包含类名与方法名的字符串</returns>
        public static string GetClassAndMethodName(int index)
        {
            StackTrace trace = new StackTrace();
            StackFrame frame = trace.GetFrame(index);
            MethodBase method = frame.GetMethod();
            String className = method.ReflectedType.Name;
            return string.Format("ClassName:{0}\tMethodName:{1}\r\n Exception Message:", className, method.Name);
        }

        /// <summary>
        /// 清楚用户Session
        /// </summary>
        public static void ClearUserSession()
        {
            if (HttpContext.Current.Session["User"] != null)
                HttpContext.Current.Session["User"] = null;
            HttpContext.Current.Response.Redirect("../index.aspx");
        }
    }
}
